package user.zc.service;

import user.zc.config.user.config.ConnectionConfig;
import user.zc.config.value.KeyValue;
import user.zc.execute.ValidationQuery;
import user.zc.util.ConfigGroupHelper;
import user.zc.util.ConnectPool;
import java.util.List;
import java.util.Map;

/**
 * @author zhouchuang
 * @date 2023/8/9 14:47
 */
public class ConnectService {

    public List<String> connectList()throws Exception{
        return ConfigGroupHelper.getInst().get(ConnectionConfig.class).list();
    }

    public void switchConnections(String connection)throws Exception {
        ConfigGroupHelper.getInst().switchConnection(connection);
        System.out.println(ConfigGroupHelper.getInst().get(ConnectionConfig.class).getUser());
    }

    public void saveOrUpdate(String connection,Map<String, KeyValue> map)throws Exception{
        ConfigGroupHelper.getInst().saveConnection(connection,map);
    }

    public Boolean validationQuery()throws Exception {
        return ConnectPool.execute(new ValidationQuery());
    }

    public ConnectionConfig read()throws Exception {
        return ConfigGroupHelper.getInst().get(ConnectionConfig.class);
    }

    public Map<String,KeyValue> read(String connection)throws Exception {
        return ConfigGroupHelper.getInst().get(ConnectionConfig.class).read(connection);
    }

    public void deleteConection(String name)throws Exception{
        ConfigGroupHelper.getInst().deleteConection(name);
    }

}
